package com.example.viewmodelstudio.databindingAdapter;

import android.graphics.Color;
import android.text.TextUtils;
import android.widget.ImageView;

import androidx.databinding.BindingAdapter;

import com.example.viewmodelstudio.R;
import com.squareup.picasso.Picasso;

public class ImageViewBindingAdapter {
    //加载网络图片
    @BindingAdapter("image")
    public static void setImage(ImageView imageView, String url) {
        if (!TextUtils.isEmpty(url)) {
            Picasso.get().load(url).placeholder(R.mipmap.ic_launcher).into(imageView);
        } else {
            imageView.setBackgroundColor(Color.YELLOW);
        }
    }
    //加载本地图片
    @BindingAdapter("image")
    public static void setImage(ImageView imageView,int resId){
        imageView.setImageResource(resId);
    }

}